﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows; 
using Microsoft.Practices.Composite.UnityExtensions;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Composite.Modularity;
using XbdSoft.WPFVersion.ViewModel;
using Microsoft.Practices.Composite.Events;
using System.Diagnostics;
using XbdSoft.Contract;
using XbdSoft.Client;

namespace XbdSoft.WPFVersion
{
    public class Bootstrapper : UnityBootstrapper
    {
        public int InitializeDownloadID { get; set; }

        protected override DependencyObject CreateShell()
        {
            var properties = Application.ResourceAssembly.GetName().Version;
            var shell = Container.Resolve<Shell>();

            var loginWindow = new LoginWindow();
            loginWindow.ShowDialog();

            if (loginWindow.HasLogin)
            {
                shell.HasLogin = true;
                shell.Show();
                if (InitializeDownloadID > 0)
                {
                    shell.Download(InitializeDownloadID);
                }
                return shell;
            }
            else
            {
                Process.GetCurrentProcess().Kill();
                return null;
            }
        }

        protected override void InitializeModules()
        {
            //IModule moduleA = Container.Resolve<ModuleA.ModuleA>();  
            //moduleB.Initialize();
        }

        protected override void ConfigureContainer()
        {
            base.ConfigureContainer();
            var eventAggregator = Container.Resolve<IEventAggregator>();

            var downloadViewModel = new DownloadViewModel(eventAggregator,Container);
            Container.RegisterInstance<DownloadViewModel>(downloadViewModel);

            var recommendDownloadViewModel = new RecommendDownloadViewModel(eventAggregator, Container);
            Container.RegisterInstance<RecommendDownloadViewModel>(recommendDownloadViewModel);
        }

        
    }
}
